#include<stdio.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<unistd.h>
#include<string.h>
#include<errno.h>
#include<netinet/in.h>
#define ERR_EXIT(m)  \
    do\
    {\
    perror(m);\
    exit(EXIT_FAILURE);\
    }while(0)




int main (void)
{
    int sockfd;
    if( (sockfd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == -1 )
        ERR_EXIT("socket");

    struct sockaddr_in servaddr;
    memset(&servaddr,0,sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(3000);
    servaddr.sin_addr.s_addr = inet_addr("192.168.99.123");

    if(connect(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr)) <0)
        ERR_EXIT("connect");
    char recvbuf[1024] = {0};
    char sendbuf[1024] = {0};
    
    while (fgets(sendbuf,sizeof(sendbuf),stdin) != NULL)
    {
        write(sockfd,sendbuf,strlen(sendbuf));
        read(sockfd,recvbuf,sizeof(recvbuf));
        printf("读取到的数据为：%s\n",recvbuf);

        memset(recvbuf,0,sizeof(recvbuf));
        memset(sendbuf,0,sizeof(sendbuf));

    }
    
    close(sockfd);


    return 0;
}